import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
 //栈实现队列
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue() {
        stack1=new Stack<>();
        stack2=new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if(empty()){
            return -1;
        }
        if(!stack2.empty()){
            return stack2.pop();
        }else{
            while(!stack1.empty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public int peek() {
        if(empty()){
            return -1;
        }
        if(!stack2.empty()){
            return stack2.peek();
        }else{
            while(!stack1.empty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        return stack1.isEmpty()&&stack2.isEmpty();
    }
}

//循环队列
class MyCircularQueue {

    public int front=0;
    public int rear=0;
    public int[] elem;
    public MyCircularQueue(int k) {
        elem=new int[k+1];
    }

    public boolean enQueue(int value) {
        if (isFull()){
            return false;
        }
        elem[rear]=value;
        rear=(rear+1)%elem.length;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()){
            return false;
        }
        front=(front+1)%elem.length;
        return true;
    }

    public int Front() {
        if (isEmpty()){
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if (isEmpty()){
            return -1;
        }
        int index=rear==0?elem.length-1:rear-1;
        return elem[index];
    }

    public boolean isEmpty() {
        return front==rear;
    }

    public boolean isFull() {
        return (rear+1)%elem.length==front;
    }
}

//用队列实现栈
class MyStack {
   public Queue<Integer> queue1;
  public   Queue<Integer> queue2;

    public MyStack() {
        queue1 = new LinkedList<>();
        queue2 = new LinkedList<>();
    }

    public void push(int x) {
        if (!queue1.isEmpty()) {
            queue1.offer(x);
        } else if (!queue2.isEmpty()) {
            queue2.offer(x);
        } else {
            queue1.offer(x);
        }
    }

    public int pop() {
        if (empty()) {
            return -1;
        }
        if (!queue1.isEmpty()) {
            int size=queue1.size();
            for (int i = 0; i < size - 1; i++) {
                int val=queue1.poll();
                queue2.offer(val);
            }
            return queue1.poll();
        } else {
            int size= queue2.size();
            for (int i = 0; i < size - 1; i++) {
                int val=queue2.poll();
                queue1.offer(val);
            }
            return queue2.poll();
        }
    }

    public int top() {
        if (empty()) {
            return -1;
        }
        if (!queue1.isEmpty()) {
            int size= queue1.size();
            int val = -1;
            for (int i = 0; i < size; i++) {
                val = queue1.poll();
                queue2.offer(val);
            }
            return val;
        } else {
            int size= queue2.size();
            int val = -1;
            for (int i = 0; i < size; i++) {
                val = queue2.poll();
                queue1.offer(val);
            }
            return val;
        }
    }

    public boolean empty() {
        return queue1.isEmpty() && queue2.isEmpty();
    }
}

public class Test {
    public static void main(String[] args) {
//        Stack<Integer> stack=new Stack<>();
//        stack.push(12);
//        stack.push(23);
//        System.out.println(stack.peek());
//        System.out.println(stack.pop());
//        System.out.println(stack.peek());
//        System.out.println(stack.empty());
        Queue<Integer> queue=new LinkedList<>();

    }
}
